import { defineStore } from 'pinia'
import type { RouteRecordRaw } from 'vue-router'

interface UserState {
    token: string
    userInfo: Record<string, any>
    routes: RouteRecordRaw[]
    perms: string[]
}

export const useUserStore = defineStore('user', {
    state: (): UserState => ({
        token: '123',
        userInfo: {},
        routes: [],
        perms: [],
    }),
    actions: {
        login(params: Record<string, any>) {
            const { username, password } = params
        },
        async getUserInfo() {
            const res = {
                user: {
                    name: 'admin',
                    avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
                    email: 'admin@admin.com',
                    signature: '海纳百川，有容乃大',
                    title: '管理员',
                },
                routes: [
                    {
                        path: '/admin',
                        name: 'admin',
                        component: "admin/index",
                        hidden: false,
                    }
                ], 
                perms: [],
            }
            this.userInfo = res.user
            this.routes = res.routes
            this.perms = res.perms
            return res
        }
    }
})

export default useUserStore
